home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / ViePratique / ArchiFacile / ArchiFacileSetup.exe / {app} / nw.pak / Unnamed File 001163.txt < prev    next >
Text File  |  2014-10-14  |  6KB  |  178 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var v8_util = process.binding('v8_util');
  22.  
  23. function Menu(option) {
  24.   if (typeof option != 'object')
  25.     option = { type: 'contextmenu' };
  26.  
  27.   if (option.type != 'contextmenu' && option.type != 'menubar')
  28.     throw new String('Invalid menu type: ' + option.type);
  29.  
  30.   this.type = option.type;
  31.   v8_util.setHiddenValue(this, 'items', []);
  32.   nw.allocateObject(this, option);
  33. }
  34. require('util').inherits(Menu, exports.Base);
  35.  
  36. Menu.prototype.__defineGetter__('items', function() {
  37.   return v8_util.getHiddenValue(this, 'items');
  38. });
  39.  
  40. Menu.prototype.__defineSetter__('items', function(val) {
  41.   throw new String('Menu.items is immutable');
  42. });
  43.  
  44. Menu.prototype.append = function(menu_item) {
  45.   if (v8_util.getConstructorName(menu_item) != 'MenuItem')
  46.     throw new String("Menu.append() requires a valid MenuItem");
  47.     
  48.   this.items.push(menu_item);
  49.   nw.callObjectMethod(this, 'Append', [ menu_item.id ]);
  50. };
  51.  
  52. Menu.prototype.insert = function(menu_item, i) {
  53.   this.items.splice(i, 0, menu_item);
  54.   nw.callObjectMethod(this, 'Insert', [ menu_item.id, i ]);
  55. }
  56.  
  57. Menu.prototype.remove = function(menu_item) {
  58.   var pos_hint = this.items.indexOf(menu_item);
  59.   nw.callObjectMethod(this, 'Remove', [ menu_item.id, pos_hint ]);
  60.   this.items.splice(pos_hint, 1);
  61. }
  62.  
  63. Menu.prototype.removeAt = function(i) {
  64.   nw.callObjectMethod(this, 'Remove', [ this.items[i].id, i ]);
  65.   this.items.splice(i, 1);
  66. }
  67.  
  68. Menu.prototype.popup = function(x, y) {
  69.   nw.callObjectMethod(this, 'Popup', [ x, y ]);
  70. }
  71.  
  72. if (require('os').platform() === 'darwin'){
  73.   Menu.prototype.createMacBuiltin = function (app_name, options) {
  74.     var appleMenu = new Menu(),
  75.         options = options || {};
  76.     appleMenu.append(new exports.MenuItem({
  77.         label: nw.getNSStringFWithFixup("IDS_ABOUT_MAC", app_name),
  78.         selector: "orderFrontStandardAboutPanel:"
  79.     }));
  80.     appleMenu.append(new exports.MenuItem({
  81.         type: "separator"
  82.     }));
  83.     appleMenu.append(new exports.MenuItem({
  84.         label: nw.getNSStringFWithFixup("IDS_HIDE_APP_MAC", app_name),
  85.         selector: "hide:",
  86.         key: "h"
  87.     }));
  88.     appleMenu.append(new exports.MenuItem({
  89.         label: nw.getNSStringFWithFixup("IDS_HIDE_OTHERS_MAC", app_name),
  90.         selector: "hideOtherApplications:",
  91.         key: "h",
  92.         modifiers: "cmd-alt"
  93.     }));
  94.     appleMenu.append(new exports.MenuItem({
  95.         label: nw.getNSStringWithFixup("IDS_SHOW_ALL_MAC"),
  96.         selector: "unhideAllApplications:",
  97.     }));
  98.     appleMenu.append(new exports.MenuItem({
  99.         type: "separator"
  100.     }));
  101.     appleMenu.append(new exports.MenuItem({
  102.         label: nw.getNSStringFWithFixup("IDS_EXIT_MAC", app_name),
  103.         selector: "closeAllWindowsQuit:",
  104.         key: "q"
  105.     }));
  106.     this.append(new exports.MenuItem({ label:'', submenu: appleMenu}));
  107.  
  108.     if (!options.hideEdit) {
  109.       var editMenu = new Menu();
  110.       editMenu.append(new exports.MenuItem({
  111.           label: nw.getNSStringWithFixup("IDS_EDIT_UNDO_MAC"),
  112.           selector: "undo:",
  113.       key: "z"
  114.       }));
  115.       editMenu.append(new exports.MenuItem({
  116.           label: nw.getNSStringWithFixup("IDS_EDIT_REDO_MAC"),
  117.           selector: "redo:",
  118.       key: "z",
  119.       modifiers: "cmd-shift"
  120.       }));
  121.       editMenu.append(new exports.MenuItem({
  122.           type: "separator"
  123.       }));
  124.       editMenu.append(new exports.MenuItem({
  125.           label: nw.getNSStringWithFixup("IDS_CUT_MAC"),
  126.           selector: "cut:",
  127.       key: "x"
  128.       }));
  129.       editMenu.append(new exports.MenuItem({
  130.           label: nw.getNSStringWithFixup("IDS_COPY_MAC"),
  131.           selector: "copy:",
  132.       key: "c"
  133.       }));
  134.       editMenu.append(new exports.MenuItem({
  135.           label: nw.getNSStringWithFixup("IDS_PASTE_MAC"),
  136.           selector: "paste:",
  137.       key: "v"
  138.       }));
  139.       editMenu.append(new exports.MenuItem({
  140.           label: nw.getNSStringWithFixup("IDS_EDIT_DELETE_MAC"),
  141.           selector: "delete:",
  142.       key: ""
  143.       }));
  144.       editMenu.append(new exports.MenuItem({
  145.           label: nw.getNSStringWithFixup("IDS_EDIT_SELECT_ALL_MAC"),
  146.           selector: "selectAll:",
  147.       key: "a"
  148.       }));
  149.       this.append(new exports.MenuItem({ label: nw.getNSStringWithFixup("IDS_EDIT_MENU_MAC"), 
  150.                                          submenu: editMenu}));
  151.     }
  152.  
  153.     if (!options.hideWindow) {
  154.       var winMenu = new Menu();
  155.       winMenu.append(new exports.MenuItem({
  156.           label: nw.getNSStringWithFixup("IDS_MINIMIZE_WINDOW_MAC"),
  157.           selector: "performMiniaturize:",
  158.       key: "m"
  159.       }));
  160.       winMenu.append(new exports.MenuItem({
  161.           label: nw.getNSStringWithFixup("IDS_CLOSE_WINDOW_MAC"),
  162.           selector: "performClose:",
  163.       key: "w"
  164.       }));
  165.       winMenu.append(new exports.MenuItem({
  166.           type: "separator"
  167.       }));
  168.       winMenu.append(new exports.MenuItem({
  169.           label: nw.getNSStringWithFixup("IDS_ALL_WINDOWS_FRONT_MAC"),
  170.           selector: "arrangeInFront:",
  171.       }));
  172.       this.append(new exports.MenuItem({ label: nw.getNSStringWithFixup("IDS_WINDOW_MENU_MAC"), 
  173.                                          submenu: winMenu}));
  174.     }
  175.   }
  176. }
  177. exports.Menu = Menu;
  178.